package com.dgut.usermodule.web;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dgut.common.util.ExtPageable;
import com.dgut.usermodule.entity.Log;
import com.dgut.usermodule.entity.LogListDTO;
import com.dgut.usermodule.service.LogService;

@RestController
@RequestMapping("/log")
public class LogCtrl {
	@Autowired
	private LogService service;
	/**
	 * 分页查询当前账户的日志
	 * @param pageable
	 * @return
	 */
	@RequestMapping("/findMyLog")
	public Page<Log> findMyLog(ExtPageable pageable) {
		pageable.setSort("logId");
		//用户没有登录，返回空
		if (SecurityUtils.getSubject().getPrincipal()==null) {
			return null;
		}
		//用户登录，返回个人日志
		pageable.setSort("logId");
		return service.findByName((String)SecurityUtils.getSubject().getPrincipal(),pageable.getPageable());
	}
	/**
	 * 分页查询所有日志
	 * @param dto
	 * @param pageable
	 * @return
	 */
	@RequestMapping("/findall")
	public Page<Log> findAll(LogListDTO dto,ExtPageable pageable){
		pageable.setSort("logId");
		return service.findAll(LogListDTO.getSpecification(dto), pageable.getPageable());
	}
}
